
program chapter6_1
    implicit none
    doubleprecision x,y,y1
    integer n,factorial
    n=1
    y=0
    y1=0
    print *, 'input x'
    read (*,*) x
    do while(abs(y-y1) .GT. 1e-15)
        y1=(-1)**(n-1)*x**(2*n-1)/factorial(n)
        y=y+y1
        n=n+1
    end do

    print *,'x=',x, 'y=',y
    print *,'sin(x)=',sin(x)

end program

integer function factorial(n)
    !factorial of 2n-1
    integer i
    factorial=1
    do i=1,2*n-1
        factorial=factorial*i
    end do
end function
